module.exports = {
    isMobile() {            //是否是移动端
        let reg = /Android|webOS|iPhone|iPod|BlackBerry/i;
        if(reg.test(navigator.userAgent)) {
            return true;
        }
    },
    checkPhone(val) {       //校验手机号是否正确 false == 有误 true == 正确
        let reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
        return reg.test(val);
    },
	openLayerIframe(obj) {
		parent.layer.open({
            type: 2,
            title: obj['title'],
            shade: 0.3,
            shadeClose: true,
            zIndex: obj['zIndex'],
            maxmin: true,
            anim: 0,
            fixed: true,
            area: [obj['width'], obj['height']],
            content: obj['url']
        });
	},
    isIE() {
        if((!!window.ActiveXObject || "ActiveXObject" in window)){
            return true;
        }
    },
    copyData(textarea, msg) {            //复制数据，safari下不支持  注意，文本区域使用textarea标签，然后使用xxx.select()方法
        if(navigator.userAgent.indexOf("MSIE") >= 0) {       //IE下
            window.clipboardData.setData('text', textarea.value);
            alert(msg);
        } else if("ActiveXObject" in window) {      //IE Edge下
            window.clipboardData.setData('text', textarea.value);
            alert(msg);
        } else {
            textarea.select();
            document.execCommand('Copy');           //调用浏览器复制命令
            alert(msg);
        }
    },
    currentDate() {             //得到当前时间 xxxx-xx-xx
        let date = new Date(),
            year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate();
        if(month < 10) month = '0' + month;
        if(day < 10) day = '0' + day;
        return year + '-' + month + '-' + day;
    },
    tfMoneyToUpperCase(val) {           //将人民币转为大写
        if(!/^(0|[1-9]\d*)(\.\d+)?$/.test(val)) return false;
        val = Number(val).toFixed(2);
        let unit = '千百拾亿千百拾万千百拾元角分', str = '';
        val += '00';
        let p = val.indexOf('.');
        if(p >= 0) 
            val = val.substring(0, p) + val.substr(p + 1, 2);
            unit = unit.substr(unit.length - val.length);
        for (let i = 0; i < val.length; i++)
            str += '零壹贰叁肆伍陆柒捌玖'.charAt(val.charAt(i)) + unit.charAt(i);
        return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
    },
    formatNumberRgx(val) {          //金额千分号
        var parts = val.toString().split(".");
        parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        return parts.join(".");
    },
    errorChar(val) {        //是否包含非法字符  true == 包含非法字符
        let reg = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;
        return reg.test(val)
    }
}